#ifndef SENSOR_H
#define SENSOR_H

#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#define REAL_TIME_DISTANCE 0x00//实时距离寄存器

#include <Wire.h>
#include <avr/io.h>
#include <avr/interrupt.h>

class SENSOR {

  private:
    int pinIn, pinEcho, pinTrig; //红外线引脚，超声波测宽引脚，超声波触发引脚

    //Laser related var
    uint8_t RX_BUF[2] = {0}; //接收数据缓冲区
    uint16_t distance = 0;//距离
    uint16_t high_byte = 0;
    uint16_t low_byte = 0;

    //Laser IIC
    String IICWrite(uint8_t addr, uint8_t*datbuf, uint16_t cnt);
    void IICRead(uint8_t addr, uint8_t* datbuf, uint16_t cnt);

    //Ultrasonic related var
    unsigned long Time_Echo_us = 0;
    unsigned long Len_mm = 0;
    int lenSum = 0;

  public:
    SENSOR(int pinin, int pinecho, int pintrig); //构造函数，A0 8 9
    void init();//初始化
    int InfraredRead();//读取红外线传感器
    int LaserRead();//读取激光传感器
    int UltrasonicRead();//读取超声波传感器


};
#endif
